##############################
#   无限冒险v2.0   
#   by Jerry Yang      
#   UUZ0226            
#############################
import pygame
import time
import game_function as gf
import hero_function as hf
from pygame.sprite import Group
from settings import Settings
from hero import Hero
from game_stats import GameStats
from button import Button

def run_game():
    # 初始化并创建一个屏幕对象
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("无限冒险v2.0")
    #创建角色
    hero = Hero(ai_settings,screen)
    #创建技能/普攻
    skills = Group()
    #创建敌人
    enemys = Group()
    # 创建一个用于存储统计信息的实例
    stats = GameStats(ai_settings)
    #创建敌人攻击
    enemyattacks = stats.enemyattacks
    #创建按钮
    cb = Button(ai_settings, screen)
    #开始界面
    gf.update_welcome_screen(ai_settings, screen)
    #生成一个信息
    hf.welcome(stats)
    #主循环
    while True:
        #检查按键
        gf.check_events(ai_settings, screen,stats, hero,skills,cb)
        if not stats.game_active:
            gf.update_information_screen(ai_settings, screen,stats,cb)
            hf.show_information(ai_settings,screen,stats,'left')
            if stats.restart_flag:
                hf.welcome(stats)
                stats.restart_flag = False
                continue
        else:
            
            gf.update_skills(ai_settings,skills,stats,screen,
                            enemyattacks,enemys)
            #敌人
            gf.create_fleet(ai_settings,
                            stats,screen, enemys)
            # 每次循环时都重绘屏幕
            gf.update_screen(ai_settings, screen,stats,
                            hero,skills,enemyattacks,enemys)
        
        
run_game()
